local daxing = fk.CreateSkill {
  name = "lingling__daxing",
}

Fk:loadTranslationTable{
  ["lingling__daxing"] = "大兴",
  [":lingling__daxing"] = "准备阶段，你可以选择令一名其他角色：摸一张牌并弃置X张牌；摸X张牌并弃置一张牌（X为你已损失体力）。",

  ["#lingling__daxing-choose"] = "大兴：你可以令一名其他角色：摸%arg张牌然后弃置一张牌，或摸一张牌然后弃置%arg张牌",
  ["lingling__daxing-draw"] = "摸%arg张牌，弃置1张牌",
  ["lingling__daxing-discard"] = "摸1张牌，弃置%arg张牌",
}

daxing:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(daxing.name) and player.phase == Player.Start and
      player:isWounded() and #player.room:getOtherPlayers(player, false) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = daxing.name,
      prompt = "#lingling__daxing-choose:::"..player:getLostHp(),
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local n = player:getLostHp()
    local choices = {"lingling__daxing-draw:::" .. n, "lingling__daxing-discard:::" .. n}
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = daxing.name,
    })
    if choice:startsWith("lingling__daxing-draw") then
      to:drawCards(n, daxing.name)
      if not to.dead then
        room:askToDiscard(to, {
          skill_name = daxing.name,
          cancelable = false,
          min_num = 1,
          max_num = 1,
          include_equip = true,
        })
      end
    else
      to:drawCards(1, daxing.name)
      if not to.dead then
        room:askToDiscard(to, {
          skill_name = daxing.name,
          cancelable = false,
          min_num = n,
          max_num = n,
          include_equip = true,
        })
      end
    end
  end,
})

return daxing
